package net.xo68.destiny.starter.worker.handler.buildin;

import lombok.extern.slf4j.Slf4j;
import net.xo68.destiny.contract.domain.job.AbortParameter;
import net.xo68.destiny.contract.domain.job.TriggerParameter;
import net.xo68.destiny.contract.domain.report.DatagramSerializer;
import net.xo68.destiny.core.timingwheel.process.EventProcessorContext;
import net.xo68.destiny.starter.worker.SchedulerWorkerProperties;
import net.xo68.destiny.starter.worker.handler.JobHandleReplyProvider;
import net.xo68.destiny.starter.worker.handler.impl.AbstractJobHandler;
import org.springframework.stereotype.Component;

/**
 * 内置处理器：测试处理器
 * @author wuxie
 * @version 2020-10-28
 */
@Slf4j
@Component("testJobHandler")
public class TestJobHandler extends AbstractJobHandler {

    public TestJobHandler(SchedulerWorkerProperties schedulerWorkerProperties, JobHandleReplyProvider jobHandleReplyProvider, DatagramSerializer datagramSerializer) {
        super(schedulerWorkerProperties,jobHandleReplyProvider,datagramSerializer);
    }

    @Override
    public void execute(EventProcessorContext<TriggerParameter> processorContext) throws Exception {
        log.info("处理任务，参数{}", processorContext.triggerParameter());
        for (int i=0; i< 10; i++){
            jobLogger.log("{} 处理任务，参数{}",i, processorContext.triggerParameter());
        }

        processorContext.setResult("testJobHandler");
    }

    @Override
    public boolean abort(AbortParameter abortParameter) {
        log.info("终止任务，参数{}", abortParameter);
        return false;
    }
}
